/*******************************************************************************
  Copyright(c) 2009 Geoffrey Hausheer. All rights reserved.

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the Free
  Software Foundation; either version 2 of the License, or (at your option)
  any later version.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59
  Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  The full GNU General Public License is included in this distribution in the
  file called LICENSE.

  Contact Information: dso-tonight-at-phracturedblue-dot-com
*******************************************************************************/

package dsotonight;

import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;

/**
 *
 * @author ghaushe
 */
public class SkyDBImage {

    private Hashtable imagemap;

    SkyDBImage() {
        try {
            URL url = this.getClass().getResource("/dsotonight/resources/image_url.dat");
            parseData(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void parseData(URL url) {
        imagemap = new Hashtable();
        try {
            LineNumberReader lnr = new LineNumberReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = lnr.readLine()) != null) {
                if (line.startsWith("#") || line.length() == 0) {
                    continue;
                }
                String elems[] = line.split(":", 3);
                if (elems.length != 3) {
                    continue;
                }
                Hashtable obj = (Hashtable) imagemap.get(elems[0]);
                if (obj == null) {
                    obj = new Hashtable();
                    imagemap.put(elems[0], obj);
                }
                obj.put(elems[1], elems[2]);
            }

        } catch (Exception e) {
        }
    }
    public Hashtable findImages(ArrayList<String>names) {
        if(names == null) {
            return null;
        }
        for(Iterator i = names.iterator(); i.hasNext();) {
            String key = (String)i.next();
            Hashtable images = (Hashtable)imagemap.get(key);
            if(images != null) {
                return images;
            }
        }
        return null;
    }
}
